smartbuck6 2.2.0
Loading...
Searching...
No Matches
smartbuck6.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef SMARTBUCK6_H
29#define SMARTBUCK6_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define SMARTBUCK6_REG_STATUS_0 0x00
74#define SMARTBUCK6_REG_STATUS_1 0x01
75#define SMARTBUCK6_REG_BUCK_A_CURR_PWR_METER 0x02
76#define SMARTBUCK6_REG_BUCK_B_CURR_PWR_METER 0x03
77#define SMARTBUCK6_REG_BUCK_C_CURR_PWR_METER 0x04
78#define SMARTBUCK6_REG_BUCKX_VOLTAGE 0x06
79#define SMARTBUCK6_REG_CLEAR_0 0x07
80#define SMARTBUCK6_REG_CLEAR_1 0x08
81#define SMARTBUCK6_REG_MASK_0 0x09
82#define SMARTBUCK6_REG_MASK_1 0x0A
83#define SMARTBUCK6_REG_REMOTE 0x0B
84#define SMARTBUCK6_REG_BUCKX_CTRL 0x0C
85#define SMARTBUCK6_REG_PG 0x0D
86#define SMARTBUCK6_REG_DISCHARGE_R 0x0E
87#define SMARTBUCK6_REG_SW_FREQ 0x0F
88#define SMARTBUCK6_REG_MONITOR_EN 0x10
89#define SMARTBUCK6_REG_SOFT_STOP_EN 0x11
90#define SMARTBUCK6_REG_SOFT_STOP 0x12
91#define SMARTBUCK6_REG_SOFT_START 0x13
92#define SMARTBUCK6_REG_PROTECT 0x14
93#define SMARTBUCK6_REG_BUCK_A_VOUT 0x15
94#define SMARTBUCK6_REG_BUCK_B_VOUT 0x16
95#define SMARTBUCK6_REG_BUCK_C_VOUT 0x17
96#define SMARTBUCK6_REG_PON_CONFIG_0 0x19
97#define SMARTBUCK6_REG_PON_CONFIG_1 0x1A
98#define SMARTBUCK6_REG_PON_CONFIG_2 0x1B
99#define SMARTBUCK6_REG_PON_CONFIG_3 0x1C
100#define SMARTBUCK6_REG_PON_OFF_DELAY0 0x1D
101#define SMARTBUCK6_REG_PON_SEQ_DELAY_1_2 0x1E
102#define SMARTBUCK6_REG_PON_SEQ_DELAY_3_PG 0x1F
103#define SMARTBUCK6_REG_POFF_SEQ_CONFIG_0 0x20
104#define SMARTBUCK6_REG_POFF_SEQ_CONFIG_1 0x21
105#define SMARTBUCK6_REG_POFF_SEQ_CONFIG_2 0x22
106#define SMARTBUCK6_REG_POFF_SEQ_CONFIG_3 0x23
107#define SMARTBUCK6_REG_ADC_TEMP 0x24
108#define SMARTBUCK6_REG_VOUT_RANGE_SEL 0x25
109#define SMARTBUCK6_REG_OC_STATUS_CLEAR 0x2A
110#define SMARTBUCK6_REG_MTP_AUTO 0x30
111#define SMARTBUCK6_REG_PART_ID 0x31
112#define SMARTBUCK6_REG_CODE_ID 0x35
113#define SMARTBUCK6_REG_CODE_VERSION 0x36
114#define SMARTBUCK6_REG_ACTIVE_POS_EN_A_B 0x71
115#define SMARTBUCK6_REG_I2C_ADDRESS 0x73
116#define SMARTBUCK6_REG_ACTIVE_POS_EN_C 0x79
117#define SMARTBUCK6_REG_VIN_OV 0x90
118#define SMARTBUCK6_REG_VIN_UVLO 0xAF
119 // smartbuck6_reg
121
126
131
136#define SMARTBUCK6_STATUS_0_OVER_TEMP_STATUS 0x40
137#define SMARTBUCK6_STATUS_0_BUCK_A_PWR_NOT_GOOD 0x20
138#define SMARTBUCK6_STATUS_0_BUCK_B_PWR_NOT_GOOD 0x10
139#define SMARTBUCK6_STATUS_0_BUCK_C_PWR_NOT_GOOD 0x08
140#define SMARTBUCK6_STATUS_0_VIN_OV 0x02
141
146#define SMARTBUCK6_STATUS_1_BUCK_A_OV 0x80
147#define SMARTBUCK6_STATUS_1_BUCK_B_OV 0x40
148#define SMARTBUCK6_STATUS_1_BUCK_C_OV 0x20
149#define SMARTBUCK6_STATUS_1_BUCK_A_UV 0x08
150#define SMARTBUCK6_STATUS_1_BUCK_B_UV 0x04
151#define SMARTBUCK6_STATUS_1_BUCK_C_UV 0x02
152
157#define SMARTBUCK6_CLEAR_0_BUCK_A_PWR_NOT_GOOD 0x20
158#define SMARTBUCK6_CLEAR_0_BUCK_B_PWR_NOT_GOOD 0x10
159#define SMARTBUCK6_CLEAR_0_BUCK_C_PWR_NOT_GOOD 0x08
160#define SMARTBUCK6_CLEAR_0_VIN_OVP 0x02
161#define SMARTBUCK6_CLEAR_0_GLOBAL 0x01
162
167#define SMARTBUCK6_CLEAR_1_BUCK_A_OV 0x80
168#define SMARTBUCK6_CLEAR_1_BUCK_B_OV 0x40
169#define SMARTBUCK6_CLEAR_1_BUCK_C_OV 0x20
170#define SMARTBUCK6_CLEAR_1_BUCK_A_UV 0x08
171#define SMARTBUCK6_CLEAR_1_BUCK_B_UV 0x04
172#define SMARTBUCK6_CLEAR_1_BUCK_C_UV 0x02
173
178#define SMARTBUCK6_OC_STATUS_CLEAR_BUCK_A_OC 0x80
179#define SMARTBUCK6_OC_STATUS_CLEAR_BUCK_B_OC 0x40
180#define SMARTBUCK6_OC_STATUS_CLEAR_BUCK_C_OC 0x20
181#define SMARTBUCK6_OC_STATUS_BUCK_A_OC 0x08
182#define SMARTBUCK6_OC_STATUS_BUCK_B_OC 0x04
183#define SMARTBUCK6_OC_STATUS_BUCK_C_OC 0x02
184
189#define SMARTBUCK6_BUCKX_CTRL_BUCK_C_EN 0x20
190#define SMARTBUCK6_BUCKX_CTRL_BUCK_B_EN 0x40
191#define SMARTBUCK6_BUCKX_CTRL_BUCK_A_EN 0x80
192#define SMARTBUCK6_BUCKX_CTRL_BUCK_X_EN_MASK 0xE0
193#define SMARTBUCK6_BUCKX_CTRL_PWM_BUCK_C_AUTO 0x02
194#define SMARTBUCK6_BUCKX_CTRL_PWM_BUCK_B_AUTO 0x04
195#define SMARTBUCK6_BUCKX_CTRL_PWM_BUCK_A_AUTO 0x08
196
201#define SMARTBUCK6_VOUT_RANGE_SEL_BUCK_C_15MV 0x02
202#define SMARTBUCK6_VOUT_RANGE_SEL_BUCK_B_15MV 0x04
203#define SMARTBUCK6_VOUT_RANGE_SEL_BUCK_A_15MV 0x08
204#define SMARTBUCK6_VOUT_RANGE_SEL_BUCK_X_MASK 0x0E
205
210#define SMARTBUCK6_PART_ID 0x13
211
216#define SMARTBUCK6_BUCK_C 0x01
217#define SMARTBUCK6_BUCK_B 0x02
218#define SMARTBUCK6_BUCK_A 0x04
219#define SMARTBUCK6_BUCK_ALL 0x07
220
225#define SMARTBUCK6_VOUT_MV_MIN 400
226#define SMARTBUCK6_VOUT_MV_MAX 3600
227#define SMARTBUCK6_VOUT_MV_STEP_THRESHOLD 1200
228#define SMARTBUCK6_VOUT_MV_STEP_10MV 10
229#define SMARTBUCK6_VOUT_MV_STEP_15MV 15
230
235#define SMARTBUCK6_IOUT_RES_MV 125
236
242#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_11 0x07
243#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_ZZ 0x08
244#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_00 0x09
245#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_0Z 0x0A
246#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_01 0x0B
247#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_Z0 0x0C
248#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_Z1 0x0D
249#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_10 0x0E
250#define SMARTBUCK6_DEVICE_ADDRESS_A2A1_1Z 0x0F
251 // smartbuck6_set
253
258
263
268#define SMARTBUCK6_MAP_MIKROBUS( cfg, mikrobus ) \
269 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
270 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
271 cfg.on = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
272 cfg.pg = MIKROBUS( mikrobus, MIKROBUS_INT )
273 // smartbuck6_map // smartbuck6
276
281typedef struct
282{
283 uint8_t status_0;
284 uint8_t status_1;
285 uint8_t oc_status;
286
288
293typedef struct
294{
295 // Output pins
296 digital_out_t on;
297
298 // Input pins
299 digital_in_t pg;
300
301 // Modules
302 i2c_master_t i2c;
303
304 // I2C slave address
306
308
313typedef struct
314{
315 pin_name_t scl;
316 pin_name_t sda;
317
318 pin_name_t on;
319 pin_name_t pg;
320
321 uint32_t i2c_speed;
322 uint8_t i2c_address;
323
325
336
342
353
368
382
394err_t smartbuck6_write_reg ( smartbuck6_t *ctx, uint8_t reg, uint8_t data_in );
395
407err_t smartbuck6_read_reg ( smartbuck6_t *ctx, uint8_t reg, uint8_t *data_out );
408
418
428
438
449
462
473
484err_t smartbuck6_enable_buck ( smartbuck6_t *ctx, uint8_t buck_sel );
485
496err_t smartbuck6_disable_buck ( smartbuck6_t *ctx, uint8_t buck_sel );
497
510err_t smartbuck6_set_buck_vout ( smartbuck6_t *ctx, uint8_t buck_sel, uint16_t vout_mv );
511
523err_t smartbuck6_read_buck_current ( smartbuck6_t *ctx, uint8_t buck_sel, uint16_t *current_ma );
524
525#ifdef __cplusplus
526}
527#endif
528#endif // SMARTBUCK6_H
529 // smartbuck6
531
532// ------------------------------------------------------------------------ END
err_t smartbuck6_init(smartbuck6_t *ctx, smartbuck6_cfg_t *cfg)
Smart Buck 6 initialization function.
err_t smartbuck6_check_com(smartbuck6_t *ctx)
Smart Buck 6 check communication function.
err_t smartbuck6_disable_buck(smartbuck6_t *ctx, uint8_t buck_sel)
Smart Buck 6 disable selected buck function.
uint8_t smartbuck6_get_pg_pin(smartbuck6_t *ctx)
Smart Buck 6 get power-good pin function.
err_t smartbuck6_default_cfg(smartbuck6_t *ctx)
Smart Buck 6 default configuration function.
err_t smartbuck6_set_buck_vout(smartbuck6_t *ctx, uint8_t buck_sel, uint16_t vout_mv)
Smart Buck 6 set output voltage function.
err_t smartbuck6_read_buck_current(smartbuck6_t *ctx, uint8_t buck_sel, uint16_t *current_ma)
Smart Buck 6 read buck output current function.
err_t smartbuck6_enable_buck(smartbuck6_t *ctx, uint8_t buck_sel)
Smart Buck 6 enable selected buck function.
void smartbuck6_disable_device(smartbuck6_t *ctx)
Smart Buck 6 disable device function.
void smartbuck6_enable_device(smartbuck6_t *ctx)
Smart Buck 6 enable device function.
err_t smartbuck6_clear_status(smartbuck6_t *ctx)
Smart Buck 6 clear status flags function.
err_t smartbuck6_read_status(smartbuck6_t *ctx, smartbuck6_status_t *status)
Smart Buck 6 read status registers function.
err_t smartbuck6_read_reg(smartbuck6_t *ctx, uint8_t reg, uint8_t *data_out)
Smart Buck 6 read register function.
err_t smartbuck6_write_reg(smartbuck6_t *ctx, uint8_t reg, uint8_t data_in)
Smart Buck 6 write register function.
void smartbuck6_cfg_setup(smartbuck6_cfg_t *cfg)
Smart Buck 6 configuration object setup function.
smartbuck6_return_value_t
Smart Buck 6 Click return value data.
Definition smartbuck6.h:331
@ SMARTBUCK6_OK
Definition smartbuck6.h:332
@ SMARTBUCK6_ERROR
Definition smartbuck6.h:333
Smart Buck 6 Click configuration object.
Definition smartbuck6.h:314
uint32_t i2c_speed
Definition smartbuck6.h:321
pin_name_t on
Definition smartbuck6.h:318
pin_name_t scl
Definition smartbuck6.h:315
pin_name_t sda
Definition smartbuck6.h:316
pin_name_t pg
Definition smartbuck6.h:319
uint8_t i2c_address
Definition smartbuck6.h:322
Smart Buck 6 Click status object.
Definition smartbuck6.h:282
uint8_t status_0
Definition smartbuck6.h:283
uint8_t status_1
Definition smartbuck6.h:284
uint8_t oc_status
Definition smartbuck6.h:285
Smart Buck 6 Click context object.
Definition smartbuck6.h:294
digital_out_t on
Definition smartbuck6.h:296
i2c_master_t i2c
Definition smartbuck6.h:302
uint8_t slave_address
Definition smartbuck6.h:305
digital_in_t pg
Definition smartbuck6.h:299